package com.blue.fish.tiny.parser.util;

import com.blue.fish.tiny.parser.ast.ASTNode;
import org.apache.commons.lang3.NotImplementedException;

/**
 * @author QingFan
 * @version 1.0.0
 * @date 2023年02月12日 16:23
 */
public class ParserUtils {

    public static String toPostPrefixExpression(ASTNode node) {
        // left op right -> left right op
        String leftStr = "";
        String rightStr = "";
        switch (node.getType()) {
            case BINARY_EXPR:
                leftStr = toPostPrefixExpression(node.getChild(0));
                rightStr = toPostPrefixExpression(node.getChild(1));
                return leftStr + " " + rightStr + " " + node.getLexeme().getValue();
            case VARIABLE:
            case SCALAR:
                return node.getLexeme().getValue();
        }
        throw new NotImplementedException("Not impl.");
    }
}
